home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Buffers / Buffer.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  1.0 KB  |  54 lines  |  [TEXT/CWIE]

  1. // Buffer.h
  2.  
  3. #ifndef Buffer_h
  4. #define Buffer_h
  5.  
  6. #ifndef Data_h
  7. #include "Data.h"
  8. #endif
  9. #ifndef ConstData_h
  10. #include "ConstData.h"
  11. #endif
  12.  
  13. class ConstBuffer;
  14.  
  15. class Buffer
  16.   {
  17.     private:
  18.         Data space;
  19.         uint32 mark;
  20.     
  21.         // not implemented:
  22.             Buffer( const Buffer& );
  23.             void operator=( const Buffer& );
  24.         
  25.     public:
  26.         Buffer( Data );
  27.         
  28.         void Reset()                            { mark = 0; }
  29.         void Reset( Data );
  30.  
  31.         inline void AdvanceMark( uint32 amount );
  32.         
  33.         ConstData Used() const                { return space.Head( mark ); }
  34.         Data Unused() const                    { return space.Tail( mark ); }
  35.         
  36.         uint32 TotalLength() const            { return space.Length(); }
  37.         uint32 UsedLength() const            { return mark; }
  38.         uint32 UnusedLength() const        { return space.Length() - mark; }
  39.         
  40.         bool IsEmpty() const                    { return mark == 0; }
  41.         bool IsFull() const                    { return mark >= space.Length(); }
  42.         
  43.         void operator<<( ConstData );
  44.         void operator<<( ConstBuffer& );
  45.   };
  46.  
  47. inline void Buffer::AdvanceMark( uint32 amount )
  48.   {
  49.     Assert( amount <= UnusedLength() );
  50.     mark += amount;
  51.   }
  52.  
  53. #endif
  54.